home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
453
/
edemo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-16
|
3KB
|
109 lines
/*
*
* edemo.c - simple RTX event management example
*
* Description:
* The root process spawns a "pitcher" process at a lower
* priority, which loops signaling events, based on
* input from the console.
*
* Each time the pitcher sends a signal, it is preempted
* by root running at the higher priority. Root receives
* the event and toggles the appropriate event flag and
* displays the status of the event flags on the screen.
*
* For demonstration purposes, root waits for the signal
* with a 30 second timeout, to show how that mechanism
* works.
*
* When all flags become enabled, the program terminates.
*/
#include <stdio.h>
#include <osbind.h>
#include <rtxbind.h>
char *root;
pitcher()
{
char c;
int event;
/* loop forever */
for (;;) {
/* get a key */
c = Cnecin();
if (c < '0' || c > '7')
continue;
/* signal event 0 through 7 */
event = 1 << (c - '0');
e_signal(root, event);
}
}
main()
{
struct config config;
int event;
int flags;
config.max_proc = 4;
config.max_queues = 1;
config.max_msgs = 1;
config.create_call = 0;
config.delete_call = 0;
config.switch_call = 0;
root = rtx_install(&config);
/* spawn pitcher process */
p_create("pitcher", 200, 100, pitcher, 0, (int *)0, 4096L);
printf("\033H\033J");
printf("+-----+-----+-----+-----+-----+-----+-----+-----+\n");
printf("| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |\n");
printf("+-----+-----+-----+-----+-----+-----+-----+-----+\n");
printf("\n+-----+-----+-----+-----+-----+-----+-----+-----+\n");
printf("\n\n\n\nThis is a simple demo of RTX events.\n");
printf("One process waits for events from another.\n");
printf("\nPress a number from 0 to 7 to signal an event.\n");
printf("When all events have been signaled, this demo quits.\n");
printf("If you take longer than 30 seconds to press a key,\n");
printf("the receiver will timeout, which just shows how a\n");
printf("process can take appropriate action to handle it.\n");
/* clear event mask */
flags = 0;
do {
/* display event flags */
printf("\033H\n\n\n");
for (event = 128; event; event >>= 1) {
if (flags & event)
printf("| ON ");
else
printf("| OFF ");
}
printf("|");
/* wait for all events (mask=255) */
event = 255;
/* wait maximum of 30 seconds (6000 1/200 sec ticks) */
if (e_wait(&event, 0, 6000L)) {
printf("\007\033H\n\n\n\n\n\033K **** TIMEOUT ****");
p_pause(5000L);
printf("\007\033H\n\n\n\n\n\033K");
}
else {
/* toggle event flag */
flags ^= event;
}
} while (flags != 255);
printf("\033H\033J");
rtx_remove();
}